<template>
    <div class="create-page">
        <div class="title">{{title}}</div>
        <div class="step-container">
            <Step :active="step" :data="stepLine" @on-click="setStep"/>
        </div>
        <div class="content" v-for="(item) in comp" :key="item.key">
            <component
                v-if="item.key == step" 
                :mooc-topic="moocTopic"
                @setStep="setStep" 
                :is="item.ins" 
                :key="item.key"
            >
            </component>
        </div>
    </div>
</template>
/**
 * query参数： 
 * 
 * id:专题id，编辑时需要
 * step:第几步，编辑时控制要跳到哪一步，1/2
 */
<script setup>
import { ref, reactive, watch, onBeforeMount } from 'vue'
import BaseInfo from './part/base-info.vue'
import Design from './part/design.vue'
import Step from './components/step.vue'
import { useRoute } from 'vue-router';

const route = useRoute();
let moocTopic = ref({})

const comp = [
    {ins: BaseInfo, key: 1},
    {ins: Design, key: 2}
]
// 步骤条
const stepLine = reactive([
    {title: '基本信息', step: 1},
    {title: '设置慕课列表', step: 2}
])
const title = ref('创建专题')
// 当前步骤
let step = ref(1)
let onlyCurrent = ref()

function setStep(val){
    step.value = val
}
watch(() => route.name, (newVal) => {
    if (route.query && route.query.id) {
        moocTopic.value.id = route.query.id;
    }
}, { 
    immediate: true
})


onBeforeMount(() => {
    step.value = route.query.step || 1;
    if (route.query && route.query.id) {
        stepLine[0].title = '编辑基本信息';
        title.value = '编辑专题'
    }
})

</script>

<style lang="scss" rel="stylesheet/scss" scoped>
.create-page{
    width: 100%;
    height:auto;
    border-radius: 4px;
    // padding-bottom: 40px;
    box-sizing: border-box;
    // background-color: #fff;
    overflow: hidden;
}
.step-container{
    background-color: #fff;
    width:100%;
    padding-top: 28px;
    padding-bottom: 25px;
    box-sizing: border-box;
    border-bottom: 1px solid #E0E2E4;
    border-radius: 4px 4px 0 0;
}
.content{
    border-radius: 10px;
}
.title {
    font-size: 18px;
    font-family: MicrosoftYaHei-Bold, MicrosoftYaHei;
    font-weight: bold;
    color: #222222;
    line-height: 24px;
    margin-top: -4px;
    margin-bottom: 16px;
}
 
</style>

